let info = document.querySelector(".info");
function main() {
    let res1;
    // let data;
    ajax({
        url: "http://chst.vip:1234/api/getcoupon",
        success(res) {
            // console.log(res);
            //数组
            res1 = res.result;
            let currentArr1 = res1;
            let html = "";
            currentArr1.forEach(item => {
                html += `
                            <a href="${item.couponLink}?couponId=${item.couponId}">
                                <img src="${item.couponImg}" alt="">
                                <p>${item.couponTitle}</p>
                            </a>
                    `
            })
            info.innerHTML = html
        },
        error(err, xhr) {
            console.log(err);
        }
    })
    // console.log(res);//异步的,这里是得不到返回的结果的
}
main()


// 点击回到顶部
let backTop = document.querySelector('.footer-main>div>a')
backTop.onclick = function(e){
    e.preventDefault()    
    let distans = document.documentElement.scrollTop
    // console.log(distans);
    let distansControl = setInterval(function(){
      distans -= 10
      document.documentElement.scrollTop = distans
      if(distans <= 0){
        clearInterval(distansControl)
      }
    },3)  
}